package com.drojian.demo4;
import android.content.Context;
import android.content.DialogInterface;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import androidx.appcompat.app.AlertDialog;

import com.drojian.demo.R;

public class AlertDialogUtils {
    public static void showDialog(Context context, String title, String hint1, String hint2, final DialogInputCallback callback) {
        View dialogContentView = LayoutInflater.from(context).inflate(R.layout.dialog_edit_layout, null);
        final EditText et1 = dialogContentView.findViewById(R.id.etdialoginput1);
        final EditText et2 = dialogContentView.findViewById(R.id.etdialoginput2);

        et1.setHint(hint1 != null ? hint1 : "输入1");
        et2.setHint(hint2 != null ? hint2 : "输入2");

        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        builder.setView(dialogContentView);
        builder.setTitle(title != null ? title : "请输入信息");

        builder.setNegativeButton("cancel", null);

        builder.setPositiveButton("ok", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (callback != null) {
                    callback.onInputConfirmed(et1.getText().toString().trim(), et2.getText().toString().trim());
                }
            }
        });

        builder.show();
    }

}
